package com.cc.common.utils;

import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

public class ResponseData<T> implements Serializable {
    /**
     * 状态码；0=成功，其他的都是失败
     */
    @ApiModelProperty(value = "状态码：0=成功，其他的失败", example = "0")
    private int code = 0;
    /**
     * 提示信息
     */
    @ApiModelProperty(value = "提示信息", example = "success")
    private String message;
    /**
     * 返回数据
     */
    @ApiModelProperty(value = "返回数据")
    private T data;

    @ApiModelProperty(value = "执行成功状态")
    private Boolean success;

    public ResponseData() {
        code = 0;
        message = "success";
        data = null;
    }

    public ResponseData(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseData(int code, String message, T data, Boolean success) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.success = success;
    }

    public ResponseData(int code, String msg) {
        this(code, msg, null);
    }

    public ResponseData(T data) {
        this(0, "success", data);
    }

    public static ResponseData success() {
        return new ResponseData(0, "success", null, true);
    }
    public static ResponseData success(String message,boolean success) {
        return new ResponseData(0, message, null, success);
    }

    public static ResponseData success(Object data) {
        return new ResponseData(0, "success", data, true);
    }

    public static ResponseData error(int code, String message) {
        return new ResponseData(code, message, null, false);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }
}

